package login;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Login {
	
    public static void main(String[] args) throws Exception {
      correctEmailAndPasswordTest();
      Thread.sleep(300);
      correctEmailAndWrongPasswordTest();
      Thread.sleep(300);
      emptyEmailAndCorrectPasswordTest();
      Thread.sleep(300);
      emptyPasswordAndCorrectEmailTest();
      Thread.sleep(300);
      emptyFieldsTest();
      Thread.sleep(300);
      scriptInjectionsAttackTest();
      Thread.sleep(300);
      htmlTagsAttackTest();
      Thread.sleep(300);
      sqlInjectionsAttackTest();
      
    }
    
    public static void correctEmailAndPasswordTest(){
      WebDriver driver = new FirefoxDriver();
        
      driver.get("https://www.snapsation.com/login");
        
      WebElement login = driver.findElement(By.name("email"));
      login.sendKeys("damczechowski@gmail.com");
      WebElement login2 = driver.findElement(By.name("password"));
      login2.sendKeys("admin123");
      login.submit();
    }
    
    public static void correctEmailAndWrongPasswordTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("damczechowski@gmail.com");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("blebleble");
        login.submit();
    }
    
    public static void emptyEmailAndCorrectPasswordTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("admin123");
        login.submit();
    }
    
    public static void emptyPasswordAndCorrectEmailTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("damczechowski@gmail.com");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("");
        login.submit();
    }
    
    public static void emptyFieldsTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("");
        login.submit();
    }
    
    public static void scriptInjectionsAttackTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("<script>alert('hello world');</script>");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("admin123");
        login.submit();
    }
    
    public static void htmlTagsAttackTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("<table><tr><td>Hello world</td></tr></table>");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("admin123");
        login.submit();
    }
    
    public static void sqlInjectionsAttackTest(){
        WebDriver driver = new FirefoxDriver();
          
        driver.get("https://www.snapsation.com/login");
          
        WebElement login = driver.findElement(By.name("email"));
        login.sendKeys("x' AND id IS NULL; --");
        WebElement login2 = driver.findElement(By.name("password"));
        login2.sendKeys("admin123");
        login.submit();
    }
    
    
}